#include <stdio.h>

char *mystrstr(const char *s1, const char *s2);

int main(int argc, char *argv[])
{
	char *ptr;
	// argv[1] --->长串 argv[2]--->子串
	if (argc < 3)
		return 1;
	ptr = mystrstr(argv[1], argv[2]);
	if (NULL == ptr) {
		printf("%s没有出现在%s\n", argv[2], argv[1]);
	} else {
		printf("find it:%s\n", ptr);
	}

	return 0;
}

char *mystrstr(const char *s1, const char *s2)
{
	const char *sp1, *sp2;

	while (*s1) {
		if (*s1 == *s2) {
			// s1 = "hewollo world hhhhh"; s2 = "world"	
			sp1 = s1 + 1;
			sp2 = s2 + 1;
			while (*sp2 && *sp1 == *sp2) {
				sp1++;
				sp2++;
			}
			if (*sp2 == '\0') {
				// s2就是s1的子串
				return (char *)s1;
			}
		}
		s1++;
	}	

	return NULL;
}


